<template>
  <Card style="width:100%" class="detail-content-layout mb16">
    <template #title>
      {{ $t('投标') }}{{info.jumpFlag==1 ? ' '+$t('已跳过'):''}}
    </template>
    <template #extra>
      <div class="h-arrow-wrap" @click="toggle = !toggle">
        <i :class="{toggleActive:toggle}" class="iconfont zy-common-jiantou h-arrow-icon"></i>
      </div>
    </template>
    <transition name="slide-up">
      <div v-if="toggle">
        <Form ref="form" :model="form" :rules="rules" label-position="top">
          <Row :gutter="24">
            <Col span="6">
              <FormItem :label="$t('推荐的供应商')">
                <Input :disabled="disabled" clearable type="text" v-model="form.sellSupplier"
                       :placeholder="$t('请输入')"></Input>
              </FormItem>
            </Col>
            <Col span="6" class="autoHeight" v-if="approvalInfo.jumpFlag!=1">
              <FormItem :label="$t('审批邮件')" prop="biddings" >
                <uploadFile accept=".pdf,.eml,.msg" key="12" :fileList="info.biddings" :disabled="disabled"
                            @change="(list)=>{form.biddings = list;}"/>
              </FormItem>
            </Col>
            <Col span="6">
              <FormItem :label="$t('备注')">
                <Input :disabled="disabled" clearable type="text" v-model="form.remark"
                       :placeholder="$t('请输入')"></Input>
              </FormItem>
            </Col>
            <Col span="6" v-if="disabled">
              <FormItem :label="$t('提交人')">
                <Input disabled clearable type="text" v-model="form.submitByStr" :placeholder="$t('请输入')"></Input>
              </FormItem>
            </Col>
            <Col span="6" v-if="disabled">
              <FormItem :label="$t('提交时间')">
                <Input disabled clearable type="text" v-model="form.submitTime" :placeholder="$t('请输入')"></Input>
              </FormItem>
            </Col>
          </Row>
        </Form>
        <rejectInfo :rejectFlows="rejectFlows"/>
      </div>
    </transition>
  </Card>
</template>

<script>
import uploadFile from "@/views/devBasic/capex/components/uploadFile";
import mixins from "@/views/devBasic/capex/components/mixins";
import rejectInfo from "@/views/devBasic/capex/components/rejectInfo";

export default {
  name: "bidding",
  components: {uploadFile, rejectInfo},
  mixins: [mixins],
  props: {
    info: {
      type: Object,
      default: () => {
      }
    },
    disabled: {
      type: Boolean,
      default: false
    },
    approvalInfo: {
      type: Object,
      default: () => {
      }
    },
    rejectFlows: {
      type: Object,
      default: () => {}
    },
  },
  data() {
    const validateFile = (rule, value, callback) => {
      if (!(Array.isArray(this.form.biddings) && this.form.biddings.length > 0)) {
        callback(new Error(this.$t('请上传附件')));
      } else {
        callback();
      }
    };
    return {
      toggle: true,
      form: {},
      rules: {
        biddings: [{required: true, validator: validateFile, trigger: 'change'}]
      }
    }
  },
  created() {
    this.form.submitByStr = this.userName;
    const {submitRemark} = this.approvalInfo
    if ((Array.isArray(this.info.biddings) && this.info.biddings.length > 0) || submitRemark ||  this.info.sellSupplier){
      this.setParams()
    }
    if (this.disabled) {
      this.toggle = false
    }else if (this.rejectFlows && this.rejectFlows.approvalRemark){
      this.toggle = true
    }
  },
  methods: {
    setParams(){
      const {submitTime, submitRemark, submitByStr} = this.approvalInfo
      const {biddings,sellSupplier} = this.info;
      this.form = Object.assign(this.form, {
        remark:submitRemark,
        submitTime,
        submitByStr,
        biddings,
        sellSupplier
      })

      this.$forceUpdate()
    },
    async getParams(status) {
      const valid = status ? status : await this.$refs.form.validate()
      if (valid) {
        return {
          ...this.form
        }
      }
    }
  }
}
</script>

<style scoped lang="scss">
@import "./style";
</style>

